package com.cloud.controller;


import com.cloud.config.Log;
import com.cloud.myInterface.Factory;
import com.cloud.pojo.ReagentUser;
import com.cloud.pojo.Region;
import com.cloud.pojo.SamplingInfo;
import com.cloud.service.ReagentUserService;
import com.cloud.service.SamplingInfoService;
import com.cloud.tools.CommonResult;
import com.cloud.tools.CommonResultFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: Tangtao
 * @Date: 2022/4/14 20:54
 * @Description: Information control interface for reagent bottles
 * @ClassName: ReagentDataController
 */

@RestController
public class ReagentDataController {

    @Resource
    private ReagentUserService reagentUserService;
    @Resource
    private SamplingInfoService samplingInfoService;

    private final Factory resultFactory = new CommonResultFactory();

    /* 提交试剂瓶信息 及对应 志愿者Id */
    @Log(value = "提交试剂瓶内容")
    @PostMapping(value = "/reagent/Info")
//    @PreAuthorize("hasAnyAuthority('ReagentInfo:create')")
    public CommonResult saveReagentInfo(@RequestBody SamplingInfo samplingInfo) {
        if (samplingInfoService.saveSampleInfo(samplingInfo))
            return resultFactory.getResultInstance(200, "数据存储成功", 1);
        return resultFactory.getResultInstance(500, "数据存储失败", 0);
    }

    /* 提交试剂瓶对应的核酸检测用户信息 */
    @PostMapping(value = "/reagent/UserInfo")
//    @PreAuthorize("hasAnyAuthority('ReagentInfo:create')")
    public CommonResult saveReagentUserInfo(@RequestBody List<ReagentUser> list) {
        if (reagentUserService.saveReagentUserInfo(list))
            return resultFactory.getResultInstance(200, "保存成功", 1);
        return resultFactory.getResultInstance(500, "保存失败", 0);
    }

    @GetMapping(value = "/region/allInfo")
    public CommonResult getRegion() {
        List<Region> region = reagentUserService.getAllRegionInfo();
        return resultFactory.getResultInstance(200, "查询成功", region);
    }



}
